package com.icoopoo.modules.evn.web;

import java.util.HashMap;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import com.icoopoo.modules.evn.service.EvnService;
import com.icoopoo.utils.resultResponse.HelperResponse;

/**
 * 需要在 springmvc的配置文件中加上  引入properties 的操作
 * @作成者:icoopoo
 * @Data:2018年12月1日 下午4:09:05
*
 */
@Controller
@RequestMapping("evn")
public class EvnController {
	
	@Value("test.param.userName")
	public String userName;
	
	@Value("test.param.password")
	public String password;
	
	@Value("${test.param.evnUserNameSpringMvc}")
	public String evnUserName;
	
	@Value("${test.param.evnPasswordSpringMvc}")
	public String evnPassword;

	@Autowired
	private EvnService service;
	
	@ResponseBody
	@RequestMapping(value = "/evnParamSpringMvc",method = RequestMethod.GET)
	public Map<String, Object> evnParamSpringMvc(HttpServletRequest request, HttpServletResponse response) {
		
		Map<Object, Object> map = new HashMap<Object, Object>();
		try{
			map.put("userName", userName);
			map.put("password", password);
			map.put("evnUserName", evnUserName);
			map.put("evnPassword", evnPassword);
			request.getSession(true);
			System.out.println("打印成功！");
			System.out.println(userName);
			System.out.println(password);
			System.out.println(evnUserName);
			System.out.println(evnPassword);
			
		}catch(Exception e){
			return HelperResponse.errorMap(null);
		}
		return HelperResponse.successMap(map);
	}
	
	@ResponseBody
	@RequestMapping(value = "/evnParamSpring",method = RequestMethod.GET)
	public Map<String, Object> evnParamSpring(HttpServletRequest request, HttpServletResponse response) {
		
		try{
			service.perprotiesFile();
		}catch(Exception e){
			return HelperResponse.errorMap(null);
		}
		return HelperResponse.successMap(null);
	}
	
	@ResponseBody
	@RequestMapping(value = "/evnJavaReadProperties",method = RequestMethod.GET)
	public Map<String, Object> evnJavaReadProperties(HttpServletRequest request, HttpServletResponse response) {
		
		try{
			service.perprotiesFile();
		}catch(Exception e){
			return HelperResponse.errorMap(null);
		}
		return HelperResponse.successMap(null);
	}
}
